# -*- coding: utf-8 -*-
# @Time        :2025/3/1 14:19
# @Author      :文刀水寿
# @File        : 8_爬虫_urllib_post请求百度翻译之详细翻译.py
"""
 @Description :
"""
import urllib.request
import urllib.parse

url = 'https://fanyi.baidu.com/ait/text/translate'

headers = {
    'cookie': 'BIDUPSID=37E7FD100566DBC3BC65F3F7BDBDC4A9; PSTM=1738571532; BAIDUID=9E3BE1F1582275297787F9B02D5D4F8E:FG=1; BAIDUID_BFESS=9E3BE1F1582275297787F9B02D5D4F8E:FG=1; ZFY=UbRkXsnPsyuHe:ASSOh2DZ0QxGpABix:Ah504KQQefL7I:C; H_PS_PSSID=61027_62080_62130_62128_62168_62176_62185_62186_62181_62194_62201_62133_62325; __bid_n=195477afa15859268dab62; ppfuid=FOCoIC3q5fKa8fgJnwzbE67EJ49BGJeplOzf+4l4EOvDuu2RXBRv6R3A1AZMa49I27C0gDDLrJyxcIIeAeEhD8JYsoLTpBiaCXhLqvzbzmvy3SeAW17tKgNq/Xx+RgOdb8TWCFe62MVrDTY6lMf2GrfqL8c87KLF2qFER3obJGmxOaJD7Qr04D9rET96PX99GEimjy3MrXEpSuItnI4KD2P5vWa8VVdqKPLBckQ0WyrgwNSQKKIDdXA6eDfuiw2FTaXuvm4kBjsPuQKAUYMQPT4QF1p3AoMwTMBqF/SER/PGgLbz7OSojK1zRbqBESR5Pdk2R9IA3lxxOVzA+Iw1TWLSgWjlFVG9Xmh1+20oPSbrzvDjYtVPmZ+9/6evcXmhcO1Y58MgLozKnaQIaLfWRFwa8A3ZyTRp/cDxRMhYc94MJmBV3DqpyTuzDwSUDbMyyfzO9u0S9v0HHkJ/i4zKsdnTNS/pLMWceus0e757/UNkQhA4BJH1ZqCtXJJ8GJaKAAv3LCf1Y7/fHL3PTSf9vid/u2VLX4h1nBtx8EF07eCMhWVv+2qjbPV7ZhXk3reaWRFEeso3s/Kc9n/UXtUfNU1sHiCdbrCW5yYsuSM9SPGDZsl7FhTAKw7qIu38vFZiq+DRc8Vbf7j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Jnb2; ab_sr=1.0.1_YjJiN2QxMDc5Yjc5ZDViZGE5N2NlZjU1ZWUxN2U1NTNkNzAwYWMyODc0YjA4ZDVjNDZmZWU3YzkyNjg0N2Y1NzVkNzZiYmQyNjU2NzZhMTg3OWNkZGViZGJlMjYwZGE5ZGU4MmI1OWJmOGRmNDc3NzFjMGEzZmY3NmVmMTQ1ZDMxYTY4NzQxZGQ1NGZhYTQ3OThiYzY4ZjkyM2ZhNmUzZg==; RT="z=1&dm=baidu.com&si=579f8fde-d447-46a3-9fe9-316b95d9345c&ss=m7pteo9f&sl=d&tt=eg7&bcn=https%3A%2F%2Ffclog.baidu.com%2Flog%2Fweirwood%3Ftype%3Dperf&ld=ywaq"'
}

data = {
    'from': "en",
    'to': "zh",
    'query': "love",
    'transtype': 'realtime',
    'simple_means_flag': '3',
    'sign': '198772.518981',
    'domain': 'common'
}

# post请求的参数，必须进行编码，并且要调用encode方法
data = urllib.parse.urlencode(data).encode('utf8')

# 请求对象的定制
request = urllib.request.Request(url, data, headers)

# 模拟浏览器向服务器发送请求
response = urllib.request.urlopen(request)

# 获取响应数据
content = response.read().decode('utf8')

print(content)
